package cc.uncarbon.module.appapi.util;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Random;

public class OrderNumberGenerator {
    public static String generateOrderNumber() {
        // 获取当前时间，精确到毫秒
        String timestamp = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
        // 生成一个4位的随机数
        Random random = new Random();
        int randomNumber = 1000 + random.nextInt(9000); // 生成1000-9999之间的随机数
        // 组合时间戳和随机数生成订单号
        return timestamp + String.valueOf(randomNumber);
    }
    //String类型日期转换为LocalDate类型
    public static LocalDate getDateFromString(String date) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd");
        LocalDate today = LocalDate.now();
        int currentYear = today.getYear();
        // 解析月份和日期
        return LocalDate.parse(currentYear + "-" + date, DateTimeFormatter.ofPattern("yyyy-MM-dd"));

    }
}
